#if !defined(__CHAT_CLIENT_H__)
#    define __CHAT_CLIENT_H__

#    include <data/Message.pb.h>
#    include <data/UserInfo.pb.h>
#    include <google/protobuf/message.h>
#    include <method/Method.pb.h>
#    include <method/Request.pb.h>
#    include <method/Response.pb.h>
#    include <packge/PackgeType.pb.h>
#    include <packge/packge.h>

class ChatClient{
public:
    using String = std::string;

    using PackgeType = ::proto::packge::PackgeType;
    using Packge     = ::proto::packge::Packge;

    using Response = ::proto::method::Response;
    using Method   = ::proto::method::Method;
    using Request  = ::proto::method::Request;

    using UserInfo              = ::proto::data::UserInfo;
    using FriendInfo            = ::proto::data::FriendInfo;
    using ChatRoomInfo          = ::proto::data::ChatRoomInfo;
    using Account               = ::proto::data::Account;
    using Message               = ::proto::data::Message;
    using VerificationCode      = ::proto::data::VerificationCode;
    using VerificationCode_Type = ::proto::data::VerificationCode_Type;
    using RegisterInfo          = ::proto::data::RegisterInfo;

private:
public:
    ChatClient();
    ~ChatClient();

public:
    // 发送一个包
    void send_pack(google::protobuf::Message& msg, PackgeType type);

    // 发起一个请求
    void request(Method method, ::google::protobuf::Message& arg);
    void request(Method method, ::std::map<String, String>& args);
    void request(Method method);

    void message(Message msg);

    void Login(String account, String passowd);
    void Register(::proto::data::RegisterInfo info);
    void SendVerificationCode(String code);
    void ResendVerificationCode();
    void GetUserInfo(String userid);
    void ChangUserInfo(UserInfo info);
    void SearchAuthor(String text);
    void AddFriends(String userid);
    void DelFriends(String userid);
    void CreateGroup(ChatRoomInfo info);
    void CreateRoom(ChatRoomInfo info);
    void JoinGroup(String roomid);
    void QuitGroup(String roomid);
    void SetAccount(::proto::data::Account account);
    void SetUserInfo(UserInfo info);
    void GetFriendList();
    void GetRoomList();
    void GetRoomMembers(String roomid);
    void SearchGroup(String text);

protected:
    void pack_handler(Packge::shared_ptr pack);
    void message_handler(Packge::shared_ptr pack);
    void response_handler(Packge::shared_ptr pack);

    void response_Register(Response& res);
    void response_Login(Response& res);
    void response_GetUserInfo(Response& res);
    void response_ChangUserInfo(Response& res);
    void response_SearchAuthor(Response& res);
    void response_SearchGroup(Response& res);
    void response_AddFriends(Response& res);
    void response_DelFriends(Response& res);
    void response_CreateGroup(Response& res);
    void response_JoinGroup(Response& res);
    void response_QuitGroup(Response& res);
    void response_CreateRoom(Response& res);
    void response_SetAccount(Response& res);
    void response_SetUserInfo(Response& res);
    void response_GetFriendList(Response& res);
    void response_GetRoomList(Response& res);
    void response_GetRoomMembers(Response& res);

    virtual void send_packge(Packge::shared_ptr pack) = 0;

    virtual void onRegister(int code, String message, std::shared_ptr<UserInfo> user)                              = 0;
    virtual void onLogin(int code, String message, std::shared_ptr<UserInfo> user)                                 = 0;
    virtual void onGetUserInfo(int code, String message, std::shared_ptr<UserInfo> user)                           = 0;
    virtual void onChangUserInfo(int code, String message, std::shared_ptr<UserInfo> user)                         = 0;
    virtual void onSearchAuthor(int code, String message, std::vector<std::shared_ptr<UserInfo>> users)            = 0;
    virtual void onSearchGroup(int code, String message, std::vector<std::shared_ptr<ChatRoomInfo>> rooms)         = 0;
    virtual void onAddFriends(int code, String message, std::shared_ptr<FriendInfo> info)                          = 0;
    virtual void onDelFriends(int code, String message, String firendsId)                                          = 0;
    virtual void onCreateGroup(int code, String message, std::shared_ptr<ChatRoomInfo> room)                       = 0;
    virtual void onCreateRoom(int code, String message, std::shared_ptr<ChatRoomInfo> room)                        = 0;
    virtual void onJoinGroup(int code, String message, std::shared_ptr<ChatRoomInfo> room)                         = 0;
    virtual void onQuitGroup(int code, String message, String roomId)                                              = 0;
    virtual void onSetAccount(int code, String message)                                                            = 0;
    virtual void onSetUserInfo(int code, String message, std::shared_ptr<UserInfo> user)                           = 0;
    virtual void onGetFriendList(int code, String message, std::vector<std::shared_ptr<FriendInfo>> users)         = 0;
    virtual void onGetRoomList(int code, String message, std::vector<std::shared_ptr<ChatRoomInfo>> rooms)         = 0;
    virtual void onGetRoomMembers(int code, String message, String roomId, std::vector<std::shared_ptr<UserInfo>>) = 0;

    virtual void onMessage(std::shared_ptr<proto::data::Message> msg) = 0;
};

#endif  // __CHAT_CLIENT_H__
